import { NAvatar, type AvatarProps } from "naive-ui";
import type { BaseComponentType } from "../types";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
export type AvatarFactoryConstructorType = {
  props?: AvatarProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
  fallbackSlot?: BaseComponentType;
  placeholderSlot?: BaseComponentType;
};
export class AvatarFactory {
  private defaultSlot: BaseComponentType = null;
  private fallbackSlot: BaseComponentType = null;
  private placeholderSlot: BaseComponentType = null;

  private props: AvatarProps = {};
  private attrs: HTMLAttributes = {};
  constructor(param?: AvatarFactoryConstructorType) {
    if (param?.props) this.setProps(param.props);
    if (param?.defaultSlot) this.setDefault(param.defaultSlot);
    if (param?.fallbackSlot) this.setFallback(param.fallbackSlot);
    if (param?.attrs) this.setAttrs(param.attrs);
    if (param?.placeholderSlot) this.setPlaceholder(param.placeholderSlot);
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: AvatarProps) {
    this.props = props;
    return this;
  }

  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  setPlaceholder(component: BaseComponentType) {
    this.placeholderSlot = component;
    return this;
  }

  setFallback(component: BaseComponentType) {
    this.fallbackSlot = component;
    return this;
  }

  create() {
    return (
      <NAvatar {...this.attrs} {...this.props}>
        {{
          default: () => getSlotsDom(this.defaultSlot),
          fallback: () => getSlotsDom(this.fallbackSlot),
          placeholder: () => getSlotsDom(this.placeholderSlot),
        }}
      </NAvatar>
    );
  }
}
